﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShareList.aspx.cs" Inherits="Web.ShareList" %>

<!doctype html>
<html lang="en">
<head>
    <base target="_self" />
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <link href="yaml/core/base.min.css" rel="stylesheet" />
    <link href="yaml/forms/gray-theme.css" rel="stylesheet" />
    <link href="yaml/screen/typography.css" rel="stylesheet" />
    <!--[if lte IE 7]>
      <link rel="stylesheet" href="yaml/core/iehacks.min.css" type="text/css"/>
      <![endif]-->
    <!--[if lt IE 9]>
      <script src="yaml/lib/html5shiv/html5shiv.js"></script>
      <![endif]-->
        <script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
		<style>
      .ym-fbox{margin:6px;}
			.noAuthed{display:none;}
		</style>
		<script>
		    //取get参数
		    function getArg() {
		        var url = unescape(window.location.href);
		        var allArgs = url.split("?")[1];
		        if (allArgs != null) {
		            var args = allArgs.split("&");
		            for (var i = 0; i < args.length; i++) {
		                var arg = args[i].split("=");
		                eval('this.' + arg[0] + '="' + arg[1] + '";');
		            }
		        }
		    }
		    var urlArg = new getArg();

		    //使用数组取得已选的表格值,不含第一行(表头)
		    function getRowText() {
		        var arr = new Array();
		        for (var i = 2; i < tbFileList.rows.length; i++) {
		            var row = tbFileList.rows[i];
		            //取得CHECKBOX   
		            var objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
		            if (objCheck != null && objCheck.checked) {
		                arr[arr.length] = row.cells[0].firstChild.value;
		            }
		        }
		        return arr;
		    }
		    function AddFolder() {
		        var url = "GetInput.htm";
		        var retStr = window.showModalDialog(url, window, 'dialogWidth=350px;dialogHeight=100px;status=no;help=no;resizable=yes;');
		        if (retStr != undefined) {
		            $.ajax({ type: 'post', url: "/File.mvc/NewFolder", data: { fileClass:1, pid: urlArg.pId, folderName: retStr },
		                success: function (data, textStatus) {
		                    if (data == "Succeed") {
		                        alert("文件夹新增成功");
		                        parent.menuContent.location.href = parent.menuContent.location.href;
		                        window.location.href = window.location.href;
		                    } else { alert(data); }
		                }
		            });
		        }
		    }
		    function view(fileClass, realName, fileId) {
		        var url = "FileViewer.htm?FileClass=" + fileClass + "&docRealName=" + realName + "&fileId=" + fileId;
		        window.open(url);
		    }
		    function ReadLog(fileId) {
		        var url = "ReadLog.aspx?fileId=" + fileId;
		        window.showModalDialog(url, window, 'dialogWidth=350px;dialogHeight=550px;status=no;help=no;resizable=yes;');
		    }
		    function ToFolder(folderID, extension) {
		        if (folderID == -1) {
		            window.location = "http://192.168.1.80/ShareList.aspx" + "?pId=<%=pPid%>";
		        }
		        else if (extension == "dir") {
		            window.location.href = "ShareList.aspx?pId=" + folderID;
		        }
		        else{
		            var url = "FileDownload.aspx?fileId=" + folderID;
		            window.location.href = url;
		        }
		    }
		    function MoveTo() {
		        var arrFolderID = getRowText();
		        if (arrFolderID.length != 1) {
		            alert("一次只能移动一个文件或文件夹");
		            return false;
		        }
		        var url = 'ShareMove.aspx?id=' + arrFolderID[0];
		        var retVal = window.showModalDialog(url, window, 'dialogWidth=400px;dialogHeight=100px;status=no;help=no;');
		        if (retVal != undefined && retVal.indexOf('Succeed') >= 0) {
		            alert("文件/文件夹移动成功");
		            parent.menuContent.location.href = parent.menuContent.location.href;
		            window.location.href = window.location.href;
		        }
		    }
		    function ReName() {
		        var arrFolderID = getRowText();
		        if (arrFolderID.length != 1) {
		            alert("一次只能重命名一个文件或文件夹");
		            return false;
		        }
		        var url = "GetInput.htm";
		        var retStr = window.showModalDialog(url, window, 'dialogWidth=350px;dialogHeight=100px;status=no;help=no;resizable=yes;');
		        if (retStr != undefined) {
		            $.ajax({ type: 'post', url: "/File.mvc/Rename", data: { fileId: arrFolderID[0], name: retStr },
		                success: function (data, textStatus) {
		                    if (data == "Succeed") {
		                        alert("文件/文件夹命名成功");
		                        parent.menuContent.location.href = parent.menuContent.location.href;
		                        window.location.href = window.location.href;
		                    } else { alert(data); }
		                }
		            });
		        }
		    }
		    function Del() {
		        var arrFolderID = getRowText();
		        var strFolderID = arrFolderID.join(",");
		        if (strFolderID == "") {
		            alert("请选择要删除的文件或文件夹!");
		            return false;
		        }
		        if (confirm("如果选择删除某个文件夹,则此文件夹下的所有文件将会删除,确定删除吗")) {
		            $.ajax({ type: 'post', url: "/File.mvc/Delete", data: { strFolderID: strFolderID },
		                success: function (data, textStatus) {
		                    if (data == "Succeed") {
		                        alert("文件/文件夹删除成功!");
		                        parent.menuContent.location.href = parent.menuContent.location.href;
		                        window.location.href = window.location.href;
		                    } else { alert(data); }
		                }
		            });
		        }
		    }
		    function move(obj, direction) {
		        var tr = obj.parentElement.parentElement;
		        tbFileList.moveRow(tr.rowIndex, Math.min(Math.max(tr.rowIndex + direction, 2), tbFileList.rows.length + 1));
		    }
		    //使用数组取得所有的表格值,不含第一行(表头)
		    function getAllRowText() {
		        var arr = new Array();
		        for (var i = 2; i < tbFileList.rows.length; i++) {
		            var row = tbFileList.rows[i];
		            arr[arr.length] = row.cells[0].firstChild.value;
		        }
		        return arr;
		    }
		    function saveOrder() {
		        var arrFolderID = getAllRowText();
		        var strFolderID = arrFolderID.join(",");
		        $.ajax({ type: 'post', url: "/File.mvc/AdjustOrder", data: { strFolderID: strFolderID },
		            success: function (data, textStatus) {
		                if (data == "Succeed") { alert('顺序保存成功'); }
		            }
		        });
		    }
		    function Download() {
		        var arrFolderID = getRowText();
		        var strFolderID = arrFolderID.join(",");
		        if (arrFolderID.length==0) {
		            alert("请选择要打包下载的文件或文件夹");
		            return false;
		        }
		        $.ajax({ type: 'post', url: "/File.mvc/GetFileChoosed", data: { strFolderID: strFolderID },
		            success: function (data, textStatus) {
		                if (data.indexOf("rar")) { location.href ="TempFile/"+data; }
		            }
		        });
		    }
		</script>
	</HEAD>
	<body>
		<form runat="server">
		    <div class="<%=isAuthed %> ym-fbox">
				<input id="btnAddFolder" type="button" value="新建文件夹" onclick="AddFolder();" class="ym-button">
                <CuteWebUI:Uploader runat="server" ID="UploaderFile" InsertText="上传文件" OnFileUploaded="Uploader_File" InsertButtonStyle-CssClass="ym-button ym-primary"></CuteWebUI:Uploader>
				<input id="btnMoveTo" type="button" value="移动到" onclick="MoveTo();" class="ym-button">
                <input id="btnReName" type="button" value="重命名" onclick="ReName();" class="ym-button">
				<input id="btnDel" type="button" value="删除" onclick="Del();" class="ym-button">
                <input id="btnOrder" type="button" value="保存排序" onclick="saveOrder();" class="ym-button">
			    <input id="btnDownload" type="button" value="打包下载" onclick="Download();" class="ym-button">
		    </div>
			<asp:Repeater ID="rptList" EnableViewState="False" Runat="server">
				<HeaderTemplate>
					<table id="tbFileList" class="s1 bordertable">
						<thead>
							<TR>
								<th width="30">选择</th>
								<th>文件名称</th>
								<th width="10%">大小(KB)</th>
								<th width="10%">上传人</th>
								<th width="10%">上传日期</th>
								<th width="20%">操作</th>
								<th width="15%" class="tdOperate<%=isAuthed %>">排序</th>
							</TR>
							<tr<%=trDisplay %>>
								<td></td>
								<td class="tdLink" onclick="ToFolder(-1);"><img src='Images/totop.gif'/>返回上一层</td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td class="tdOperate<%=isAuthed %>"></td>
							</tr>
						</thead><tbody>
				</HeaderTemplate>
				<ItemTemplate>
					<tr class="<%# Container.ItemIndex%2==0?"bg":""%>">
						<td><input type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"Id") %>'></td>
						<td class="tdLink" onclick="ToFolder(<%# DataBinder.Eval(Container.DataItem,"Id") %>,'<%# DataBinder.Eval(Container.DataItem,"Type") %>');"><img src='Images/<%# getIcon(DataBinder.Eval(Container.DataItem,"Type").ToString()) %>.gif'/><%# DataBinder.Eval(Container.DataItem, "Name")%></td>
						<td><%# getSize(DataBinder.Eval(Container.DataItem, "Size"))%></td>
						<td><%# DataBinder.Eval(Container.DataItem, "EmpName")%></td>
						<td><%# DataBinder.Eval(Container.DataItem, "CreatTime", "{0:d}")%></td>
						<td class="tdOperate"><%# getLinks(DataBinder.Eval(Container.DataItem, "Id").ToString(), DataBinder.Eval(Container.DataItem, "Type").ToString(), DataBinder.Eval(Container.DataItem, "FileClass").ToString(), DataBinder.Eval(Container.DataItem, "RealName"), DataBinder.Eval(Container.DataItem, "Size"))%></td>
						<td class="tdOperate<%=isAuthed %>"><span onclick="move(this,-1);">[上移]</span><span onclick="move(this,1);">[下移]</span></td>
					</tr>
				</ItemTemplate>
				<FooterTemplate>
					</tbody> </table>
				</FooterTemplate>
			</asp:Repeater>
		</form>
	</body>
</HTML>